#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   cache.py
@Time    :   2022/11/25 14:17:16
@Author  :   youle
@Email   :   a_fly0505@163.com
@Copyright : 侵权必究
'''
import numpy as np
import datetime


class Cache:
    def __init__(self) -> None:
        self.RSI = "rsi"
        self.CCI = "cci"
        self.KDJ = "kdj"
        self.BOLL = "boll"
        self.MACD = "macd"
        self.TIME = "time"
        self.DATA = "data"
        self.store = {}

    def SetRSI(self, code: str, rsi: np.ndarray) -> bool:
        if code not in self.store:
            self.store[code] = {}
        if self.RSI not in self.store[code]:
            self.store[code][self.RSI] = {}
        self.store[code][self.RSI][self.TIME] = datetime.datetime.now()
        self.store[code][self.RSI][self.DATA] = rsi
        return True

    def GetRSI(self, code: str) -> np.ndarray:
        if code in self.store:
            if self.RSI in self.store[code]:
                return True, self.store[code][self.RSI]
        return False, []
